using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Services;


namespace DialogComponent
{
  /// <summary>
  /// This is a game component that implements IUpdateable.
  /// </summary>
  public class GameLogic : Microsoft.Xna.Framework.DrawableGameComponent
  {
    public GameLogic(Game game)
      : base(game)
    {
    }

    public override void Initialize()
    {
      var input = (Game.Services.GetService(typeof(IInputManager)) as IInputManager);
      input.OnTap += new InputManager.Tap(input_OnTap);
      input.OnPress += new InputManager.Tap(GameLogic_OnDoubleTap);
      
      base.Initialize();
    }

    void input_OnTap(Vector2 tap_position)
    {
      if (Enabled == false) return;
      this.Enabled = false;
      Game.Components.Add(new DialogComponent(Game, this));
    }

    void GameLogic_OnDoubleTap(Vector2 tap_position)
    {
      if (Enabled == false) return;
      cnt2++;
    }

    SpriteBatch sprite_batch;
    SpriteFont font;
    protected override void LoadContent()
    {
      sprite_batch = new SpriteBatch(GraphicsDevice);
      font = Game.Content.Load<SpriteFont>("Font");
      base.LoadContent();
    }

    int cnt1 = 0, cnt2 = 0;
    public override void Update(GameTime gameTime)
    {
      cnt1++;
      base.Update(gameTime);
    }

    public override void Draw(GameTime gameTime)
    {
      sprite_batch.Begin();
      sprite_batch.DrawString(font, "Game Counter = " + cnt1, new Vector2(50, 250), Color.Yellow);
      sprite_batch.DrawString(font, "Input Counter = " + cnt2, new Vector2(50, 350), Color.Yellow);
      sprite_batch.End();

      base.Draw(gameTime);
    }
  }
}
